﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace ClickToCall.ClickToCallToolbar
{
    class RegistrySettingsProvider
    {
        public string ApplicationName
        {
            get { return System.Windows.Forms.Application.ProductName; }
            set { }
        }

        public Microsoft.Win32.RegistryKey RegistryKey
        {
            get
            {
                string key = string.Empty;
                if (Environment.OSVersion.Version.Major == 6)
                {
                    key = "SOFTWARE\\AppDataLow\\Software\\" + ApplicationName + "\\Settings";
                    return Microsoft.Win32.Registry.CurrentUser.CreateSubKey(key);
                }
                else
                {
                    key = "SOFTWARE\\" + ApplicationName + "\\Settings";
                    return Microsoft.Win32.Registry.CurrentUser.CreateSubKey(key);
                }
            }
        }

        public void Save(Settings settings)
        {
            try
            {
                Microsoft.Win32.RegistryKey key = RegistryKey;

                key.SetValue("SearchOC", settings.SearchOC.ToString());
                key.SetValue("SearchOutlook", settings.SearchOutlook.ToString());
                key.SetValue("UseOCHome", settings.UseOCHome.ToString());
                key.SetValue("UseOCMobile", settings.UseOCMobile.ToString());
                key.SetValue("UseOCWork", settings.UseOCWork.ToString());
                key.SetValue("UseOlkCompany", settings.UseOlkCompany.ToString());
                key.SetValue("UseOlkHome", settings.UseOlkHome.ToString());
                key.SetValue("UseOlkMobile", settings.UseOlkMobile.ToString());
                key.SetValue("UseOlkPrimary", settings.UseOlkPrimary.ToString());
                key.SetValue("UseOlkWork", settings.UseOlkWork.ToString());
                key.SetValue("UseOlkWork2", settings.UseOlkWork2.ToString());
            }
            catch {
            }
        }

        public Settings Load()
        {
            Settings settings = new Settings();
            try
            {
                Microsoft.Win32.RegistryKey key = RegistryKey;

                settings.SearchOC = Convert.ToBoolean(key.GetValue("SearchOC", false));
                settings.SearchOutlook = Convert.ToBoolean(key.GetValue("SearchOutlook", false));
                settings.UseOCHome = Convert.ToBoolean(key.GetValue("UseOCHome", false));
                settings.UseOCMobile = Convert.ToBoolean(key.GetValue("UseOCMobile", false));
                settings.UseOCWork = Convert.ToBoolean(key.GetValue("UseOCWork", false));
                settings.UseOlkCompany = Convert.ToBoolean(key.GetValue("UseOlkCompany", false));
                settings.UseOlkHome = Convert.ToBoolean(key.GetValue("UseOlkHome", false));
                settings.UseOlkMobile = Convert.ToBoolean(key.GetValue("UseOlkMobile", false));
                settings.UseOlkPrimary = Convert.ToBoolean(key.GetValue("UseOlkPrimary", false));
                settings.UseOlkWork = Convert.ToBoolean(key.GetValue("UseOlkWork", false));
                settings.UseOlkWork2 = Convert.ToBoolean(key.GetValue("UseOlkWork2", false));

            }
            catch {
                
            }
            return settings;
        }
    }
}
